<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="../vue.js"></script>
</head>
<body>
<div id="app">
    <!--父组件-->
    <counter :count="1" @change="handleChange"></counter>
    <counter :count="2" @change="handleChange"></counter>
    <div>{{total}}</div>
</div>

<script>
//    子组件
    var counter={
        props:['count'],
        data: function () {
            return {
                number:this.count
            }
        },
        template:'<div @click="handleClick">{{number}}</div>',
        methods:{
            handleClick: function () {
                //错误,子组件不能修改父组件传递过来的参数--单向数据流
                this.number=this.number+2;
                this.$emit('change',2)
            }
        }
    }
    var vm = new Vue({
        el: "#app",
        data: {
            total:3
        },
        components:{
            counter:counter
        },
        methods:{
            handleChange: function (step) {
                this.total+=step
            }
        }
    })
</script>
</body>
</html>